import localCache from "../../../utils/cache"
import mapToObj from "../../../utils/mapToObj"
import ITask from "../types/ITask";

/**
 * 缓存中的任务数据转换到内存
 * @param prefix 任务前缀
 */
export default function cacheToData(prefix: string): Array<ITask>{
  const tempArr = <ITask[]>[]
  localCache.getAllCache<string,string>("id","title").map(item => {
    const obj = mapToObj<string,string>(item)
    if(obj.id.startsWith(prefix)){
      tempArr.push(obj)
    }
  });
  return tempArr
}